	<?php
		session_start();
		if (isset($_SESSION["elementos"])){	
			$archivo 	= "zz_nombre_pagina.php";
			$fh 		= fopen($archivo, "w");

			fwrite($fh,'<?php $titulo = "TITULO"; require "cabecera.php" ?> </head><body><?php include "menu_datos.php";include "menu_arriba.php";?> <div>');
			
			//$cant = count($_SESSION["elementos"]);
			//$i = 0;
			$lista = 0;
			
			/*$html = print_r($_SESSION["elementos"],true);
			fwrite($fh, $html);*/
			
			foreach ($_SESSION["elementos"] as $i => $fila) {
			//while ($i < $cant)
				$tipo 	= $fila[0];
				$id		= $fila[1];
				$class 	= $fila[2];
				$tx 	= $fila[3];
				$link 	= $fila[4];
				$title 	= $fila[5];
				
				$prop	= "";
				if ($id){
					$prop .= " id=\"" . $id . "\" name=\"" . $id . "\" ";
				}
				if ($class){
					$prop .= "class=\"" . $class . "\" ";
				}
				
				if ($lista == 1){
					if ($tipo == "li"){
						$tx 	= $fila[3];
						$html 	= "<li>" . $tx . "</li>";
					}
					else{
						$lista = 0;
						$html = "</ul>";
					}
				}
				
				if ($tipo == "p" || $tipo == "h2"){
					$html = "<" . $tipo . $prop . "\">" . $tx . "</" . $tipo . ">";
				}
				else {
					if ($tipo == "ul"){
						$html = "<ul><h2>" . $tx . "</h2>";
						$lista = 1;
						/*$i++;
						while ($i < $cant && $_SESSION["elementos"][$i][0] == "li"){
							$tx 	= $_SESSION["elementos"][$i][3];
							$html 	.= "<li>" . $tx . "</li>";
							$i++;
						}
						$html .= "</ul>";
						$i--;*/
					}
					else {
						if ($tipo == "img"){
							rename("php/uploads/" . $link, "images/" . $link);
							$html = "<img src=\"" . "images/" . $link . "\" " . $prop . "\"\\>";
							
						}
						else {
							if ($tipo == "a"){
								$html = "<a href=\"" . $link . "\" " . $prop . "\">" . $tx . "</a>";
							}
						}
					}
				}
				fwrite($fh, $html);
				//$i++;
			}
			if ($lista == 1)
			{
				$html = "</ul>";
				fwrite($fh, $html);
			}
			fwrite($fh,'</div><?php require "pie.php" ?></body></html>');
			fclose($fh);
			unset($_SESSION["elementos"]);
			header("location: prueba.php");
		}  
	?>
